package com.jamie.business.service.impl;

import com.jamie.api.order.OrderService;
import com.jamie.api.storage.StorageService;
import com.jamie.business.service.BusinessService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Jamie
 * @date 2020/4/13
 */
@Service
public class BusinessServiceImpl implements BusinessService {
    @Resource
    private StorageService storageService;
    @Resource
    private OrderService orderService;

    @GlobalTransactional
    @Override
    public void purchase(String userId, String commodityCode, int orderCount) {
        storageService.deduct(commodityCode, orderCount);
        orderService.create(userId, commodityCode, orderCount);
    }
}
